const http = require('http');
//连接数据库
require('./model/connect');

const path = require('path');
const template = require('art-template');
//引入router
const router = require('./route/index');
const serveStatic = require('serve-static');

const dateFormat = require('dateformat')

//创建静态资源访问服务
const serve = serveStatic(path.join(__dirname,'public'));

//配置模板
template.defaults.root = path.join(__dirname,'views');
template.defaults.extname = '.art';
template.defaults.imports.dateFormat=dateFormat;


//创建服务器
const app = http.createServer();
app.on('request',(req, res) => {
    //启动路由功能
    router(req,res,() => {});
    //启动静态资源访问功能
    serve(req, res,() => {});
});
app.listen(80);
console.log('服务器启动成功');